﻿#include <DisyEngine.hpp>
using namespace NAMESPACENAME;
// 使用带主题的控件
#if defined _M_IA64 // 安腾平台
#pragma comment(linker, "/MANIFESTDEPENDENCY:\"type='Win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='IA64' publicKeyToken='6595B64144CCF1DF'\"")
#elif defined _M_AMD64 // 64位平台
#pragma comment(linker, "/MANIFESTDEPENDENCY:\"type='Win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='AMD64' publicKeyToken='6595B64144CCF1DF'\"")
#elif defined _M_IX86 // 32位平台
#pragma comment(linker, "/MANIFESTDEPENDENCY:\"type='Win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595B64144CCF1DF'\"")
#elif defined _M_ARM // ARM平台
#pragma comment(linker, "/MANIFESTDEPENDENCY:\"type='Win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ARM' publicKeyToken='6595B64144CCF1DF'\"")
#else // 其它平台
#pragma comment(linker, "/MANIFESTDEPENDENCY:\"type='Win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595B64144CCF1DF'\"")
#endif // MANIFEST
class MyWindow final :
	public WindowForm
{
	Page* page;
	Button* button, * displayButton;
	Label* label;
	RichEdit* richEdit;
	HWND pagerControl;
public:
	MyWindow() :
		WindowForm(NAMESPACENAME::Rectangle(CW_USEDEFAULT, CW_USEDEFAULT, 1366, 768)),
		page(new Page(NAMESPACENAME::Rectangle(0, 0, 1700, 920), String(STRING("Page01")), this)),
		button(new Button(NAMESPACENAME::Rectangle(50, 50, 150, 150), String(STRING("Button")), page)),
		displayButton(new Button(NAMESPACENAME::Rectangle(50, 200, 150, 150), String(STRING("Visable")), page)),
		label(new Label(NAMESPACENAME::Rectangle(200, 50, 150, 150), String(STRING("Label")), page)),
		richEdit(new RichEdit(NAMESPACENAME::Rectangle(50, 350, 300, 150), String(STRING("RichEdit")), page))
	{
		pages.push_back(page);

		// Button Test Passed
		button->onMouseClick += &MyWindow::ButtonClick;
		button->Visibility(Control::Visibility::Visible);

		displayButton->onMouseClick += &LeftButtonClick;
		displayButton->Visibility(Control::Visibility::Visible);
		// Label Test Not Passed: Problem with Clicking
		// May be the problem of windows
		label->onMouseClick += &MyWindow::LabelClick;
		label->Visibility(Control::Visibility::Visible);
		// Click on other space of window

		//RichEdit
		richEdit->Visibility(Control::Visibility::Visible);

		//pagerControl
		pagerControl = CreateWindowExW(
			0,
			WC_PAGESCROLLERW,
			L"Pager",
			WS_CHILD | PGS_HORZ | WS_VISIBLE,
			0,
			0,
			1700,
			50,
			hWnd,
			GetId(this),
			Application::GetInstance(),
			nullptr
		);

		//DirectX部分
		//DirectXViewerControl* dxViewer(new DirectXViewerControl(String(STRING("DXViewer")), this));
		//dxViewer->Create(NAMESPACENAME::Rectangle(250, 250, 400, 300), this, L"DirectX");
		//dxViewer->visibility = Control::Visibility::Visible;
		//4、创建直接命令队列
		D3D12_COMMAND_QUEUE_DESC queueDesc = {};
		queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
		//dxViewer->CreateCommandQueue(&queueDesc);

		//5、创建交换链
		DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {};
		swapChainDesc.BufferCount = 2;
		swapChainDesc.Width = 400;
		swapChainDesc.Height = 300;
		swapChainDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
		swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
		swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
		swapChainDesc.SampleDesc.Count = 1;
		//dxViewer->CreateSwapChain(&swapChainDesc, nullptr, nullptr);

		page->Visibility(Visibility::Visible);
	}
	virtual void OnDestroy()override final
	{
		PostQuitMessage(0);
	}
	static void ButtonClick(Control* sender, EventArgs& e)
	{
		dynamic_cast<Button*>(sender)->Visibility(Control::Visibility::Hidden);
	}
	static void LabelClick(Control* sender, EventArgs& e)
	{
		dynamic_cast<Label*>(sender)->Visibility(Control::Visibility::Hidden);
	}
	static void LeftButtonClick(Control* sender, EventArgs& e)
	{
		MyWindow* win(
			dynamic_cast<MyWindow*>(
				dynamic_cast<Page*>(
					dynamic_cast<Button*>(sender)->Parent()
					)->Parent()
				)
		);
		win->label->Visibility(Visibility::Visible);
		win->button->Visibility(Visibility::Visible);
	}
};
int __stdcall wWinMain(
	HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPWSTR    lpCmdLine,
	int       nCmdShow)
{
	Application::Initialize(hInstance);
#ifdef _DEBUG
	DirectXViewerControl::Initialize(true);
#else
	DirectXViewerControl::Initialize(false);
#endif
	MyWindow win;
	win.Visibility(Control::Visibility::Visible);
	return Application::MainLoop();
}